package com.kantboot.system.user.dao.repository.entity;

import com.kantboot.system.user.domain.entity.SysBalanceChangeRecord;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface SysBalanceChangeRecordRepository
        extends JpaRepository<SysBalanceChangeRecord, Long> {

    /**
     * 根据id修改状态编码
     */
    @Transactional
    @Modifying
    @Query("""
        UPDATE SysBalanceChangeRecord
        SET statusCode = :statusCode
        WHERE id = :id
    """)
    void updateStatusCodeById(Long id, String statusCode);

    /**
     * 根据状态编码的集合查询数量
     */
    @Query("""
        SELECT COUNT(*)
        FROM SysBalanceChangeRecord
        WHERE userId = :userId AND
        statusCode IN :statusCodeIn
    """)
    Long countByUserIdAndStatusCodeIn(
            @Param("userId") Long userId,
            @Param("statusCodeIn") String... statusCodeIn);


}
